package uyun.controller;

import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CSHApplicationController {

    @Value("${key_1:default}")
    private String key1;

    @Value("${key_2}")
    private String key2;

    @GetMapping("getKey1")
    public String getKey1(){
        return "key_1 = " + key1;
    }

    @GetMapping("getKey2")
    public String getKey2(){
        return "key_2 = " + key2;
    }


    @ApolloConfigChangeListener
    private void configChangeListener(ConfigChangeEvent changeEvent) {
        for (String key : changeEvent.changedKeys()) {
            System.out.println("key:" + key + "  change to :" + changeEvent.getChange(key));
        }
    }
}
